#!/bin/sh

set -x

for dir in chroot/{dev/pts,proc,sys,var/lib/dpkg} ; do
   if mountpoint -q "$dir" ; then
      umount "$dir"
   fi
done

lb clean noauto ${@}

# rm -f build-*.log

# Remove generated files
rm -f config/binary config/bootstrap config/chroot config/common config/source

# Remove empty directories in config tree
if ls config/*/ > /dev/null 2>&1 ; then
	rmdir --ignore-fail-on-non-empty config/*/
fi

# files copied or created in the config stage
rm -f config/chroot_local-includes/etc/amnesia/environment
rm -f config/chroot_local-includes/etc/amnesia/version
rm -f config/chroot_local-includes/usr/share/doc/amnesia/Changelog
for list in config/chroot_local-packageslists/*.list ; do
   if [ "$list" != 'config/chroot_local-packageslists/tails-common.list' ]; then
      rm -f "$list"
   fi
done

# files copied or created in the build stage
rm -f config/chroot_local-includes/usr/share/amnesia/build/variables

# static wiki
rm -rf config/chroot_local-includes/usr/share/doc/tails/website wiki/src/.ikiwiki
find wiki/src -name *.pot -exec rm {} \;
